package com.wcs.util;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.IOException;

/**
 * Http抽象类
 *
 * Created by Eternal_L on 2017/11/24.
 */
public abstract class HttpUtils {

    public static CloseableHttpResponse getHtml(String url) throws IOException {

        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(url);
        // 在请求中明确定义不要进行压缩
        httpGet.setHeader("Accept-Encoding", "identity");
        CloseableHttpResponse res = null;
        try {
            res = httpClient.execute(httpGet);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 终止HttpGet执行
            httpGet.abort();
            httpClient.close();
        }
        return res;
    }
}
